﻿<navigation:Page x:Class="GroupChallenge.QuestionsView"
                 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                 xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
                 xmlns:sys="clr-namespace:System;assembly=mscorlib"
                 xmlns:local="clr-namespace:GroupChallenge"
                 mc:Ignorable="d"
                 d:DesignWidth="640"
                 d:DesignHeight="480"
                 Style="{StaticResource PageStyle}">
    <navigation:Page.Resources>
        <local:QuestionsViewModel x:Key="QuestionsViewModel" />
        <CollectionViewSource x:Key="cvsQuestions" />
    </navigation:Page.Resources>
    <Grid x:Name="LayoutRoot"
          DataContext="{Binding Source={StaticResource ResourceKey=QuestionsViewModel}}">
        <ScrollViewer x:Name="PageScrollViewer"
                      Style="{StaticResource PageScrollViewerStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="130" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                        <RowDefinition Height="35" />
                    </Grid.RowDefinitions>
                    <TextBlock Grid.Row="0"
                               Text="Question Type"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Right" />
                    <StackPanel Grid.Row="0"
                                Grid.Column="1"
                                Orientation="Horizontal"
                                VerticalAlignment="Center">
                        <RadioButton Content="Multiple Choice"
                                     Margin="8"
                                     GroupName="QuestionTypeGroup"
                                     IsChecked="{Binding Path=CurrentQuestion.QuestionTypeId, Mode=TwoWay, Converter={StaticResource QuestionTypeConverter}, ConverterParameter=MultipleChoice}" />
                        <RadioButton Content="True / False"
                                     Margin="8"
                                     GroupName="QuestionTypeGroup"
                                     IsChecked="{Binding Path=CurrentQuestion.QuestionTypeId, Mode=TwoWay, Converter={StaticResource QuestionTypeConverter}, ConverterParameter=TrueFalse}" />
                        <RadioButton Content="Verbal Explanation"
                                     Margin="8"
                                     GroupName="QuestionTypeGroup"
                                     IsChecked="{Binding Path=CurrentQuestion.QuestionTypeId, Mode=TwoWay, Converter={StaticResource QuestionTypeConverter}, ConverterParameter=Verbal}" />
                    </StackPanel>
                    <TextBlock Grid.Row="1"
                               Text="Question Text (255):"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Right" />
                    <TextBox Grid.Row="1"
                             Grid.Column="1"
                             TextWrapping="Wrap"
                             Margin="2"
                             Text="{Binding Path=CurrentQuestion.QuestionText, Mode=TwoWay}" />
                    <RadioButton Grid.Row="2"
                                 Content="Answer 1"
                                 FlowDirection="RightToLeft"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Right"
                                 GroupName="CorrectAnswerGroup"
                                 IsChecked="{Binding Path=CurrentQuestion.CorrectAnswerId, Mode=TwoWay, Converter={StaticResource BoolWithIntParameterConverter}, ConverterParameter=1}" />
                    <TextBox Grid.Row="2"
                             Grid.Column="1"
                             TextWrapping="Wrap"
                             Margin="2"
                             Text="{Binding Path=CurrentQuestion.Answer1, Mode=TwoWay}" />
                    <RadioButton Grid.Row="3"
                                 Content="Answer 2"
                                 FlowDirection="RightToLeft"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Right"
                                 GroupName="CorrectAnswerGroup"
                                 IsChecked="{Binding Path=CurrentQuestion.CorrectAnswerId, Mode=TwoWay, Converter={StaticResource BoolWithIntParameterConverter}, ConverterParameter=2}" />
                    <TextBox Grid.Row="3"
                             Grid.Column="1"
                             TextWrapping="Wrap"
                             Margin="2"
                             Text="{Binding Path=CurrentQuestion.Answer2, Mode=TwoWay}" />
                    <RadioButton Grid.Row="4"
                                 Content="Answer 3"
                                 FlowDirection="RightToLeft"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Right"
                                 GroupName="CorrectAnswerGroup"
                                 IsChecked="{Binding Path=CurrentQuestion.CorrectAnswerId, Mode=TwoWay, Converter={StaticResource BoolWithIntParameterConverter}, ConverterParameter=3}" />
                    <TextBox Grid.Row="4"
                             Grid.Column="1"
                             TextWrapping="Wrap"
                             Margin="2"
                             Text="{Binding Path=CurrentQuestion.Answer3, Mode=TwoWay}" />
                    <RadioButton Grid.Row="5"
                                 Content="Answer 4"
                                 FlowDirection="RightToLeft"
                                 VerticalAlignment="Center"
                                 HorizontalAlignment="Right"
                                 GroupName="CorrectAnswerGroup"
                                 IsChecked="{Binding Path=CurrentQuestion.CorrectAnswerId, Mode=TwoWay, Converter={StaticResource BoolWithIntParameterConverter}, ConverterParameter=4}" />
                    <TextBox Grid.Row="5"
                             Grid.Column="1"
                             TextWrapping="Wrap"
                             Margin="2"
                             Text="{Binding Path=CurrentQuestion.Answer4, Mode=TwoWay}" />
                    <TextBlock Grid.Row="6"
                               Text="Category:"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Right" />
                    <ComboBox Grid.Row="6"
                              Grid.Column="1"
                              Width="240"
                              HorizontalAlignment="Left"
                              VerticalContentAlignment="Center"
                              Margin="2"
                              SelectedValue="{Binding Path=CurrentQuestion.CategoryName, Mode=TwoWay}"
                              SelectedIndex="0">
                        <sys:String>User Interface</sys:String>
                        <sys:String>Data Binding</sys:String>
                        <sys:String>Data</sys:String>
                        <sys:String>Networking</sys:String>
                        <sys:String>Other</sys:String>
                    </ComboBox>
                    <StackPanel Grid.Row="7"
                                Grid.Column="1"
                                Orientation="Horizontal">
                        <Button Content="Insert / Update"
                                Margin="2"
                                Width="100"
                                Click="InsertUpdateQuestionButton_Click"></Button>
                        <Button Content="Delete"
                                Margin="2"
                                Width="76"
                                Click="DeleteQuestionButton_Click"></Button>
                        <Button Content="Refresh List"
                                Margin="2"
                                Width="76"
                                Click="RefreshList_Click"></Button>
                        <Button Content="Populate"
                                Margin="2"
                                Width="76"
                                Click="Populate_Click"></Button>
                        <Button Content="Save All"
                                Margin="2"
                                Width="76"
                                Click="SaveAllQuestionsButton_Click" />
                    </StackPanel>
                    <TextBlock Grid.Row="8"
                               Text="Current Question"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Right" />
                    <TextBlock Grid.Row="8"
                               Grid.Column="1"
                               x:Name="CurrentQuestionId"
                               VerticalAlignment="Center" />
                </Grid>
                <sdk:DataGrid AutoGenerateColumns="False"
                              Grid.Row="1"
                              IsReadOnly="True"
                              Name="QuestionsDataGrid"
                              SelectionChanged="QuestionsDataGrid_SelectionChanged">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTemplateColumn CanUserReorder="True"
                                                    CanUserResize="True"
                                                    CanUserSort="True"
                                                    Width="Auto"
                                                    Header="Set Current">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Content="{Binding Path=QuestionId}"
                                            Click="SetCurrentQuestionButton_Click" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTextColumn Binding="{Binding Path=QuestionText}"
                                                Header="Question"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=CategoryName}"
                                                Header="Category"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=QuestionTypeId}"
                                                Header="Question Type"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=WonByPlayerNickName}"
                                                Header="Won By Player"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=SubmittedByPlayerNickName}"
                                                Header="Submitted By"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=CorrectAnswerId}"
                                                Header="The Answer Id"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=Answer1}"
                                                Header="Answer 1"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=Answer2}"
                                                Header="Answer 2"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=Answer3}"
                                                Header="Answer 3"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=Answer4}"
                                                Header="Answer 4"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True"
                                                Width="Auto" />
                        <sdk:DataGridTextColumn Binding="{Binding Path=QuestionId}"
                                                Header="Question Id"
                                                CanUserReorder="True"
                                                CanUserResize="True"
                                                CanUserSort="True" />
                        <sdk:DataGridTemplateColumn CanUserReorder="True"
                                                    CanUserResize="True"
                                                    CanUserSort="True"
                                                    Width="Auto"
                                                    Header="Submitted Time">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Path=SubmittedTimeUTC}" />
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </Grid>
        </ScrollViewer>
    </Grid>
</navigation:Page>